import axios from "axios";
import store from "../store";

axios.interceptors.request.use(
  (config) => {
    store.state.token && (config.headers.token = store.state.token);
    store.commit("showLoading");
    return config;
  },
  (error) => {
    store.commit("hideLoading");
    return Promise.reject(error);
  }
),
  axios.interceptors.response.use(
    (response) => {
      store.commit("hideLoading");
      return response;
    },

    (error) => {
      store.commit("hideLoading");
      return Promise.reject(error);
    }
  );
export default axios;
